﻿<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" autoFlush="true"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="/WEB-INF/qa-category.tld" prefix="cat"%>
<%@ taglib uri="/WEB-INF/displaytag-el.tld" prefix="display" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<logic:present name="questiono">
    <div style="padding:0 0 7 0;">
        <span style="float:left;">
            <html:link page="/question.mrqa?action=list&catId=16">网站调研</html:link>
        </span>
        <span style="float:right;">
            <logic:present name="user_session" scope="session">
                <html:link page="/mylink.mrqa?action=add" paramId="questionId" paramName="questiono" paramProperty="id">
                    收藏
                </html:link>
            </logic:present>
        </span>
    </div>
</logic:present>
<table class="qlist" cellpadding="0" cellspacing="0" style="width:720;word-wrap:break-word;table-layout:fixed;">
    <tr>
        <td>
        <p>
        <b>
        	<c:if test="${questiono.titleAttribute != null}">
            <span style="<c:out value="${questiono.titleAttribute}" />">
           </c:if>
        	<c:out value="${questiono.title}" escapeXml="false"/>
        	<c:if test="${questiono.titleAttribute != null}">
        		</span>
           </c:if>
        </b>
        </p>
        <pre><c:out escapeXml="false" value="${questiono.content}"/></pre>
        <p>
            <logic:notEmpty property="reference" name="questiono">
                参考:<a href="<bean:write property="reference" name="questiono"/>" target="_blank"><bean:write property="reference" name="questiono"/></a>
            </logic:notEmpty>
        </p>
        <p>
            <logic:notEmpty property="fileName" name="questiono">
                附件:
                <c:set var="ufid" value="q${questiono.id}"/>
                <html:link page="/download.mrqa" paramId="id" paramName="ufid">
                    <c:out value="${questiono.fileName}"/>
                </html:link>                    
                (请谨慎判断文件类型,避免恶意侵扰,网站不负责可能造成的损坏或损失)
            </logic:notEmpty>
        </p>
        </td>
    </tr> 
    <tr>
        <td align="right">
            <c:if test="${user_session.type == '1'}">
            <!-- admin-->
                    <a href="#modifyQuestion" onclick="modifyQuestion();return false;">修改</a>
                    &nbsp;|&nbsp;
                    <a href="#answer" onclick="addAnswer();return false;">增加选项</a>&nbsp;|&nbsp;
                        <logic:notEqual value="4" name="questiono" property="state">
                            <html:link page="/question.mrqa?action=close" paramId="id" paramName="questiono" paramProperty="id" title="隐藏此帖子,避免别的用户看到（仅作者能看到此连接）,你也可以在[用户中心]重新打开此帖子">
                            隐藏
                            </html:link>
                            &nbsp;|&nbsp;
                        </logic:notEqual>
                        <logic:equal value="4" name="questiono" property="state">
                            <html:link page="/question.mrqa?action=reopen" paramId="id" paramName="questiono" paramProperty="id" title="重开此帖子,使别的用户看到（仅作者能看到此连接）">
                            打开
                            </html:link>
                            &nbsp;|&nbsp;                            
                        </logic:equal>
                <html:link page="/question.mrqa?action=delete" paramId="id" paramName="questiono" paramProperty="id" title="帖子被删除后无法恢复">
                    删除
                </html:link>
            <!-- admin -->
            </c:if>
            <hr>
        </td>
    </tr>
    <tr>
        <td width="100%">
            <c:if test="${fn:length(questiono.mrIaskAnswers) > 0}">
            <c:set var="voteTotal" value="0"/>
            <c:forEach var="answer" items="${questiono.mrIaskAnswers}">
                <c:set var="voteTotal" value="${voteTotal+answer.pollCount}"/>
            </c:forEach>
            <c:if test="${voteTotal == 0}">
                <c:set var="voteTotal" value="1"/>
            </c:if>
            <html:form action="/question"> 
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <c:forEach var="answer" items="${questiono.mrIaskAnswers}">            
               <tr>
                  <td>
                        <c:if test="${user_session != null}">
                            <c:if test="${user_session.userId != '1'}">
                                <input type="checkbox" value="<c:out value="${answer.id}"/>" name="pollItem"/>
                            </c:if>
                        </c:if>
                        <c:out value="${answer.content}"/>&nbsp;&nbsp;
                </td>
                <td width="300">
                        <img src="qa/images/votewidth.gif" alt="" height="10" width="<c:out value="${(answer.pollCount/voteTotal)*300}"/>"/>
                </td>
                <td>
                        &nbsp;<fmt:formatNumber type="number" value="${(answer.pollCount/voteTotal)*100}" pattern="0.00"/>%&nbsp;(<c:out value="${answer.pollCount}"/>票)
                        <c:if test="${user_session.type == '1'}">
                                    <span style="padding:0 0 0 6;">
                                        <html:link page="/answer.mrqa?action=delete" paramId="id" paramName="answer" paramProperty="id" title="选项删除后不能恢复">
                                        删除
                                        </html:link>
                                        <html:link page="/answer.mrqa?action=premodify" paramId="id" paramName="answer" paramProperty="id" target="modifyAnswerFrame" onclick='modifyAnswer(this);'>
                                        修改
                                        </html:link>
                                    </span>
                        </c:if>
                   </td>
                </tr>
                </c:forEach>                
                <tr>
                    <td colspan="3">
                            <hr>
                            <logic:present name="user_session" scope="session">
                            <c:if test="${user_session.loginName != questiono.mrIaskUser.loginName}">
                                <html:hidden property="action" value="vote"/>
                                <input type="hidden" name="id" value="<bean:write name="questiono" property="id"/>"/>
                                <html:submit value="我来投票"/>
                            </c:if>
                            </logic:present>
                            <logic:notPresent name="user_session" scope="session">
                                <html:submit value="我来投票" disabled="true" title="请登陆后投票"/>
                            </logic:notPresent>
                    </td>
                </tr>
            </table>
                </html:form>            
            </c:if>
        </td>
    </tr>
</table>
<c:if test="${user_session.type == '1'}">
<div id="questionDiv" style="display:none">
<a name="modifyQuestion"/>
<br>
<table class="mars" cellpadding="0" cellspacing="0">
    <html:form action="/question" method="post" enctype="multipart/form-data" onsubmit="return validateq(this);">
    <html:hidden property="action" value="modify"/>
    <input type="hidden" name="catId" value="<c:out value="${questiono.mrIaskCategory.id}"/>"/>
    <input type="hidden" name="id" value="<c:out value="${questiono.id}"/>"/>
    <tr class="even">
        <td colspan="2" align="left"><b>修改调研</b></td>
    </tr>
    <tr>
        <td align="right">标题</td>
        <td>
            <html:text property="title" name="questiono" size="60" maxlength="60"/>*
        </td>
    </tr> 
    <tr class="even">
        <td align="right">内容</td>
        <td>
            <textarea name="content" cols="50" rows="10"><c:out value="${questiono.content}" escapeXml="true"/></textarea>
        </td>
    </tr>
    <tr class="even">
        <td align="right">补充</td>
        <td>
            <textarea name="addition" cols="50" rows="3"><c:out value="${questiono.addition}" escapeXml="true"/></textarea>
        </td>
    </tr>
    <tr>
        <td align="right">参考</td>
        <td>
            <html:text property="reference" name="questiono" size="60"/>
        </td>
    </tr>
   <tr class="even">
        <td align="right">附件</td>
        <td>
            <logic:notEmpty property="fileName" name="questiono">
                原附件:
                <c:set var="ufid" value="q${questiono.id}"/>
                <html:link page="/download.mrqa" paramId="id" paramName="ufid">
                    <c:out value="${questiono.fileName}"/>
                </html:link>
                &nbsp;&nbsp;
                <html:link page="/question.mrqa?action=deletefile" paramId="id" paramName="questiono" paramProperty="id">
                        删除
                </html:link>
                <br>
            </logic:notEmpty>
            <html:file property="file" size="50"/>(如果重新上载，原文件被删除)
        </td>
    </tr>
    <tr class="even">
        <td align="right"></td>
        <td>
            <input type="submit" value="提交修改"/>
        </td>
    </tr>
    </html:form>
</table>
<script type="text/javascript">
    function validateq(pForm)
    {
        var title = pForm.title.value;
        if(title == "" || title.length < 1)
        {
            alert("[标题]必须填写，长度必须大于0");
            pForm.title.focus();
            return false;
        }
        return true;
    }
    function modifyQuestion()
    {
        var questionDiv = document.getElementById("questionDiv");
        if(questionDiv.style.display == "none")
        {
            questionDiv.style.display = "block";
            document.location.href = "#modifyQuestion";
            var questionfs = document.questionf;
            var questionf;
            for(var i=0;i<questionfs.length;i++)
            {
                questionf = questionfs[i];
                if("modify" == questionf.action.value)
                {
                    questionf.title.focus();
                    break;
                }
            }
        }
        else
            questionDiv.style.display = "none";
    }
</script>
</div>
</c:if>
<!--here topic-->
<c:if test="${user_session.type == '1'}">
<div id="modifyAnswerDiv" style="display:none;">
    <br>
    <table border="0" cellpadding="0" cellspacing="0" align="center" width="720">
        <tr style="background:url(qa/images/dothline.gif) bottom;">
            <td width="720">
            &nbsp;&nbsp;&nbsp;&nbsp;<b>修改回复</b>
            </td>
        </tr>
    </table>
    <div style="width:720;padding:12px 0px 0px 4px;border-left:1px dotted #ccc;border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;">
    <iframe src="about:blank" frameborder="0" scrolling="auto" name="modifyAnswerFrame" id="modifyAnswerFrame" width="100%" height="220"></iframe>
    </div>
    <input type="hidden" name="mafocus"/>
    <script type="text/javascript">
        function modifyAnswer(link)
        {
            var addAnswerDiv = document.getElementById("addAnswerDiv");        
            if(addAnswerDiv.style.display == "block" || addAnswerDiv.style.display == "")
                addAnswerDiv.style.display = "none";
            var modifyAnswerDiv = document.getElementById("modifyAnswerDiv");
            if(modifyAnswerDiv.style.display == "none")
                modifyAnswerDiv.style.display = "block";
            var anchor = document.getElementById("mafocus");anchor.focus();
        }
    </script>
</div>
<div id="addAnswerDiv">
<br>
<a name="addAnswer"/>
<script type="text/javascript">
    function addAnswer()
    {
        document.location.href = "#addAnswer";
    }
</script>
<span class="title1">增加选项</span>
<table align="center" width="100%" class="its" cellpadding="0" cellspacing="0">
    <html:form action="/answer" enctype="multipart/form-data" focus="content" onsubmit="return validate(this);">
    <html:hidden property="action" value="add"/>
    <input type="hidden" name="questionId" value="<bean:write name="questiono" property="id"/>"/>
   <tr>
        <td align="right">内容:<a name="answer"></a></td>
        <td>
            <html:textarea property="content" cols="65" rows="10"/>*
        </td>
    </tr>
   <!-- 
   <tr>
        <td align="right">参考</td>
        <td>
            <html:text property="reference" value="http://" size="60"/>
        </td>
    </tr>
   <tr>
        <td align="right">附件</td>
        <td>
            <html:file property="file" size="50" disabled="true"/>
        </td>
    </tr>-->
   <tr>
        <td align="right">&nbsp;</td>
        <td>
            <input type="submit" value="submit"/>
        </td>
    </tr>
    </html:form>
</table>
</div>
</c:if>
<script type="text/javascript">
    function validate(pForm)
    {
        var content = pForm.content.value;
        if(content == "" || content.length < 1)
        {
            alert("[内容]必须填写，长度必须大于0");
            pForm.content.focus();
            return false;
        }
        return true;
    }
    function onVote(pSubmit)
    {
        pSubmit.form.action = "vote";
    }
    function onSetPollItems(pSubmit)
    {
        pSubmit.form.action = "setpollitems";
    }
</script>
